<?php

namespace App\Http\Controllers\Client;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Region;
use App\Models\Store;

class RegionController extends Controller
{

    protected $regionModel;
    protected $storeModel;

    public function __construct()
    {
        $this->regionModel = new Region();
        $this->storeModel = new Store();
    }

    public function allRegion(){
        $res = $this->regionModel->getInfoList();
        return $this->success($res,'区域列表获取成功');
    }

    //获取区域列表（预约页）
    public function regionListForBookPage(Request $request){

        $store = $request->input('store') ?? '五月花NewBeauty';
        $region_id = $this->storeModel->getInfo("name",$store)['region_id'];
        $regionInfoList = $this->regionModel->getInfoList()->toArray();
        $regionNameArr = $this->toLinearArray($regionInfoList,'name');
        foreach($regionInfoList as $k=>$v){
            if($v['id'] == $region_id){
                unset($regionNameArr[$k]);
                array_unshift($regionNameArr, $v['name']);

            }
        }

        return $this->success($regionNameArr,'获取区域列表成功');
    }



}
